#include <stdio.h>
#include <stdlib.h>

typedef struct Node* PtrToNode;

struct Node {
    int Data;
    PtrToNode Next;
};

typedef int ElementType;

typedef PtrToNode Node;

Node CreateNode ();

void AddNode ( Node node, ElementType X );

void FreeNode ( Node node );

int main () {
    Node S1 = CreateNode(), S2 = CreateNode();
    int X, output = 0;
    /* read S1 */
    scanf("%d",&X);
    while( X != -1 ) {
        AddNode(S1,X);
        scanf("%d",&X);
    }
    /* read S2 */
    scanf("%d",&X);
    while( X != -1 ) {
        AddNode(S2,X);
        scanf("%d",&X);
    }
    /* find */
    Node PtrToS1 = S1->Next, PtrToS2 = S2->Next;
    while ( PtrToS1 && PtrToS2 ) {
        if ( PtrToS1->Data == PtrToS2->Data ) {
            PtrToS1 = PtrToS1->Next;
            PtrToS2 = PtrToS2->Next;
        } else if ( PtrToS1->Data > PtrToS2->Data ) {
            PtrToS2->Data = -1;
            PtrToS2 = PtrToS2->Next;
        } else {
            PtrToS1 = PtrToS1->Next;
        }
    }
    while ( !PtrToS2 ) {
        if ( PtrToS1 ) {
            PtrToS1->Data = -1;
            PtrToS1 = PtrToS1->Next;
        } else break;
    }
    while ( !PtrToS1 ) {
        if ( PtrToS2 ) {
            PtrToS2->Data = -1;
            PtrToS2 = PtrToS2->Next;
        } else break;
    }
    /* output */
    PtrToS2 = S2->Next;
    if ( !PtrToS2 ) printf("NULL");
    while ( PtrToS2 && !output ) {
        if ( PtrToS2->Data != -1 ){
            printf("%d",PtrToS2->Data);
            PtrToS2 = PtrToS2->Next;
            output = 1;
        } else PtrToS2 = PtrToS2->Next;
    }
    while ( PtrToS2 ) {
        if ( PtrToS2->Data != -1 ) {
            printf("% d",PtrToS2->Data);
        }
        PtrToS2 = PtrToS2->Next;
        
    }
    if ( output == 0 ) printf("NULL");
    else printf("\n");
    FreeNode(S1);
    FreeNode(S2);
    return 0;
}

Node CreateNode () {
    Node node;
    node = (Node)malloc(sizeof(struct Node));
    node->Data = 0;
    node->Next = NULL;
    return node;
}

void AddNode ( Node node, ElementType X ) {
    Node tmp, rear = node;
    while( rear->Next != NULL ) rear = rear->Next; 
    tmp = (Node)malloc(sizeof(struct Node));
    tmp->Data = X;
    tmp->Next = rear->Next;
    rear->Next = tmp;
}

void FreeNode ( Node node ) {
    Node tmp;
    while ( node ) {
        tmp = node;
        node = node->Next;
        free(tmp);
    }
}